﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace BLL
{

    public static class SubmitWin_hemai
    {
        static decimal oneMoney = 0;
        static decimal twoMoney = 0;
        static decimal threeMoney = 0;
        static decimal sumWinMoney = 0;
        static Model.LotteryAnnouncement la = null;
        /// <summary>
        /// 更新合买方案的状态
        /// </summary>
        public static void UpdateLotteryChippedState(int type,string qs)
        {

            //string sql = "select top 1 * from LotteryAnnouncement where LotteryType=" + type + " order by id desc";
            //Model.LotteryAnnouncement model = BLL.LotteryAnnouncement.GetModelBySql(sql);//最新开奖信息

            string sqlstr = "select * from LotteryChipped where LotteryType=" + type + " and LotteryOpenTime='" +qs + "' and Flag=0";//flag=0为未派奖
            DataTable chipDt = BLL.LotteryChipped.GetPageListBysql(sqlstr);//未派奖的合买方案

            for (int j = 0; j < chipDt.Rows.Count; j++)
            {
                int id = int.Parse(chipDt.Rows[j]["id"].ToString());

                //1.将所有方案State状态更新为True
                UpdatePlanState(id);
            }
        }
        public static void SubmitWin()
        {
            for (int i = 1; i < 8; i++)
            {
                string sql = "select top 1 * from LotteryAnnouncement where LotteryType=" + i + " order by id desc";
                Model.LotteryAnnouncement model = BLL.LotteryAnnouncement.GetModelBySql(sql);//最新开奖信息

                string sqlstr = "select * from LotteryChipped where LotteryType=" + i + " and LotteryOpenTime=" + model.LotteryQS + " and Flag=0";//flag=0为未派奖
                DataTable Chip_dt = BLL.LotteryChipped.GetPageListBysql(sqlstr);//未派奖的合买方案

                for (int j = 0; j < Chip_dt.Rows.Count; j++)
                {
                    int id = int.Parse(Chip_dt.Rows[j]["id"].ToString());
                    int userId = int.Parse(Chip_dt.Rows[j]["UserID"].ToString());
                    int LotteryMoney = int.Parse(Chip_dt.Rows[j]["LotteryMoney"].ToString());//方案金额
                    int MyGua = int.Parse(Chip_dt.Rows[j]["MyGua"].ToString());
                    int MySub = int.Parse(Chip_dt.Rows[j]["MySub"].ToString());
                    //1.将所有方案State状态更新为True
                    //UpdatePlanState(id);
                    //2.方案成功的，扣除选择预付款跟单的投注人的投注金额;方案失败，退回参与投注人的投注金额
                    if (UpdatePlanProjectStatus(id, userId, LotteryMoney, MyGua, MySub) == true)
                    {
                        //3.方案成功的，开始派奖
                        TraverseTheWinning(model.LotteryQS, model.LotteryNo, i);
                    }

                }

            }
        }
        //开奖后，统一更新合买方案为已满，即过期状态
        private static void UpdatePlanState(int FangAnId)
        {
            Model.LotteryChipped mode = BLL.LotteryChipped.GetModel(FangAnId);
            mode.State = true;
            BLL.LotteryChipped.Update(mode);

        }

        /// <summary>
        /// 判断方案成功或者失败，并更新账户
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="UserID">方案发起人ID</param>
        private static bool UpdatePlanProjectStatus(long Id, int UserID, int LotteryMoney, int MyGua, int MySub) //方案状态--判断该合买方案是否成功
        {
            string sqls = "select isnull(sum([MySub]),0) as allgdmoney from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + Id; //r如果等于NULL，赋值为O
            System.Data.DataTable dingzhiyhje = BLL.LotteryChippedUser.GetPageListBysql(sqls); //当前方案所有跟单人的跟单总金额

            if (Convert.ToInt32(dingzhiyhje.Rows[0]["allgdmoney"].ToString()) + MySub < LotteryMoney)//跟单总额+发起人购买金额<方案总额
            {
                if (MyGua > 0)//保底金额>0
                {
                    decimal dj = Convert.ToInt32(dingzhiyhje.Rows[0]["allgdmoney"].ToString()) + MySub + MyGua; //跟单总额+发起人购买金额+保底金额

                    if (Convert.ToInt32(dj) < LotteryMoney) //跟单总金额+发起人自购金额+保底金额<方案总额
                    {
                        PlanFail(Id, UserID);
                        return false;
                    }
                    else
                    {
                        PlanSuccess(Id, MyGua, UserID);
                        return true;
                    }

                }
                else
                {
                    PlanFail(Id, UserID);
                    return false;
                }
            }
            else
            {
                PlanSuccess(Id, MyGua, UserID);
                return true;
            }
        }

        /// <summary>
        /// 方案成功执行操作
        /// </summary>
        /// <param name="FangAnId">方案ID</param>
        /// <param name="MyGua">保底金额</param>
        /// <param name="UserID">方案发起人ID</param>
        private static void PlanSuccess(long FangAnId, int MyGua, int UserID)
        {
            #region 预付方案成功，把临时表中的金额，从自己当前账户减去

            string Sql11 = "select * from GenDanUser_temp where LotteryChippedid=" + FangAnId;
            DataTable dtModel2 = BLL.GenDanUser_temp.GetPageListBysql(Sql11);
            Model.UsersAccount model1 = new Model.UsersAccount();
            decimal goldCodeNum = 0;
            decimal moneyNum = 0;
            for (int i = 0; i < dtModel2.Rows.Count; i++)
            {
                model1 = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dtModel2.Rows[i]["user_id"].ToString()));
                if (model1.goldTotal < Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]))//账户中金币不足，不足部分扣账户余额
                {
                    decimal plus = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]) - model1.goldTotal;
                    goldCodeNum = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                    moneyNum = plus;
                    model1.goldTotal = 0;
                    model1.total = model1.total - plus;

                }
                else//账户中金币充足，优先扣金币
                {
                    model1.goldTotal = model1.goldTotal - Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                    goldCodeNum = Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]);
                    moneyNum = 0;
                    model1.total = model1.total;
                }
                model1.user_id = model1.user_id;
                model1.czTotal = model1.czTotal;
                model1.txTotal = model1.txTotal;
                model1.buyLotteryTotal = model1.buyLotteryTotal;
                model1.winTotal = model1.winTotal;
                model1.addtime = model1.addtime;
                model1.modellevel = model1.modellevel;
                model1.LotteryType = model1.LotteryType;

                if (BLL.UsersAccount.Update(model1) > 0)
                {
                    Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                    Cost_temp.user_id = Convert.ToInt32(dtModel2.Rows[i]["user_id"].ToString());
                    Cost_temp.LotteryChippedid = FangAnId;
                    Cost_temp.GoldCode = goldCodeNum;
                    Cost_temp.Money = moneyNum;
                    Cost_temp.AddTime = System.DateTime.Now;
                    Cost_temp.LotteryChipperFrom = 1;

                    BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱

                    InsertIngratel(Convert.ToInt32(dtModel2.Rows[i]["user_id"].ToString()), 1, "购买彩票获得" + Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]) + "分", Convert.ToDecimal(dtModel2.Rows[i]["DJJEmoney"]));
                }
            }
            #endregion
            #region 实付方案,方案成功,扣除发起人的保底金额
            Model.UsersAccount user_account1 = new Model.UsersAccount();
            user_account1 = BLL.UsersAccount.GetModelByuser_id(UserID);
            decimal goldCodeNum1 = 0;
            decimal moneyNum1 = 0;
            //如果方案成功，总金额-保底金额
            if (user_account1.goldTotal < MyGua)//账户中金币不足，剩余部分扣账户金额
            {
                decimal plus = MyGua - user_account1.goldTotal;
                goldCodeNum1 = MyGua;
                moneyNum1 = plus;
                user_account1.goldTotal = 0;
                user_account1.total = user_account1.total - plus;
            }
            else//账户中金币充足，优先扣金币
            {
                user_account1.goldTotal = user_account1.goldTotal - MyGua;
                goldCodeNum1 = MyGua;
                moneyNum1 = 0;
                user_account1.total = user_account1.total;
            }
            user_account1.user_id = user_account1.user_id;
            user_account1.czTotal = user_account1.czTotal;
            user_account1.txTotal = user_account1.txTotal;
            user_account1.buyLotteryTotal = user_account1.buyLotteryTotal;
            user_account1.winTotal = user_account1.winTotal;
            user_account1.addtime = user_account1.addtime;
            user_account1.modellevel = user_account1.modellevel;
            user_account1.LotteryType = user_account1.LotteryType;
            if (BLL.UsersAccount.Update(user_account1) > 0)
            {
                Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                Cost_temp.user_id = UserID;

                Cost_temp.LotteryChippedid = FangAnId;
                Cost_temp.GoldCode = goldCodeNum1;
                Cost_temp.Money = moneyNum1;
                Cost_temp.AddTime = System.DateTime.Now;
                Cost_temp.LotteryChipperFrom = 1;
                BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                InsertIngratel(user_account1.user_id, 1, "购买彩票获得" + MyGua + "分", MyGua);
            }
            #endregion

            Model.LotteryChipped modelfasb = new Model.LotteryChipped();
            modelfasb = BLL.LotteryChipped.GetModel(FangAnId);
            modelfasb.ProjectStatus = 2; //方案成功
            BLL.LotteryChipped.Update(modelfasb);

            string sql = "delete from GenDanUser_temp where LotteryChippedid=" + FangAnId;
            BLL.GenDanUser_temp.DeleteData(sql);
            BLL.LotteryBuyCost_temp.Delete(FangAnId);
        }
        /// <summary>
        /// 方案失败执行操作
        /// </summary>
        /// <param name="FangAnId">方案ID</param>
        /// <param name="UserID">方案发起人ID</param>
        private static void PlanFail(long FangAnId, int UserID)
        {
            #region 实付方案失败，执行操作

            string sqlstr = "select UserID,MySub from [dbo].[LotteryChippedUser] where [LotteryChippedId]=" + FangAnId + " and fkfs =2";
            DataTable dingzhifasb = BLL.LotteryChippedUser.GetPageListBysql(sqlstr);
            Model.UsersAccount user_account = new Model.UsersAccount();
            decimal goldCodeNum = 0;
            decimal moneyNum = 0;
            #region  归还实时扣钱，投注人的投注金额
            for (int i = 0; i < dingzhifasb.Rows.Count; i++)
            {
                string sqlcost = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + FangAnId + " and user_id=" + Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()) + " and  LotteryChipperFrom = 1";
                Model.LotteryBuyCost_temp cost_temp = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost);
                goldCodeNum = cost_temp.GoldCode;
                moneyNum = cost_temp.Money;

                user_account = BLL.UsersAccount.GetModelByuser_id(Convert.ToInt32(dingzhifasb.Rows[i]["UserID"].ToString()));
                user_account.goldTotal = user_account.goldTotal + goldCodeNum;
                user_account.total = user_account.total + moneyNum;
                user_account.user_id = user_account.user_id;
                user_account.czTotal = user_account.czTotal;
                user_account.txTotal = user_account.txTotal;
                user_account.buyLotteryTotal = user_account.buyLotteryTotal;
                user_account.winTotal = user_account.winTotal;
                user_account.addtime = user_account.addtime;
                user_account.modellevel = user_account.modellevel;
                user_account.LotteryType = user_account.LotteryType;
                BLL.UsersAccount.Update(user_account);

            }
            #endregion
            #region 归还方案发起人的投注金额
            decimal goldCodeNum1 = 0;
            decimal moneyNum1 = 0;
            string sqlcost1 = "select GoldCode,Money from LotteryBuyCost_temp where LotteryChippedid=" + FangAnId + " and user_id=" + UserID + " and  LotteryChipperFrom = 1";
            Model.LotteryBuyCost_temp cost_temp1 = BLL.LotteryBuyCost_temp.GetModelBysql(sqlcost1);
            if (cost_temp1 == null)
            {
                goldCodeNum1 = 0;
                moneyNum1 = 0;
            }
            else
            {
                goldCodeNum1 = cost_temp1.GoldCode;
                moneyNum1 = cost_temp1.Money;
            }
            string sqlfq = "update UsersAccount set total=total+" + moneyNum1 + ",goldTotal=" + goldCodeNum1 + "  where user_id=" + UserID;
            BLL.UsersAccount.Update(sqlfq);//归还发起人金额
            #endregion
            //预付扣款失败之后，删除临时表                             
            string sql = "delete from GenDanUser_temp where LotteryChippedid=" + FangAnId;
            BLL.GenDanUser_temp.DeleteData(sql);
            BLL.LotteryBuyCost_temp.Delete(FangAnId);

            #endregion
        }
        /// <summary>
        /// 添加积分获得使用信息表
        /// </summary>
        /// <param name="userid">用户id</param>
        /// <param name="type">1.获得，2消费</param>
        /// <param name="content">使用说明</param>
        /// <param name="userIntegral">使用积分数</param>
        private static void InsertIngratel(long userid, int type, string content, decimal userIntegral)
        {
            Model.IntegralExchange Ingratel = new Model.IntegralExchange();
            Ingratel.Type = type;
            Ingratel.UseIntegral = userIntegral;
            Ingratel.OrderId = DateTime.Now.ToString("yyyyMMddhhmmss");
            Ingratel.Addtime = DateTime.Now;
            Ingratel.Content = content;
            Ingratel.IsSuccess = true;
            Ingratel.UserId = userid;
            BLL.IntegralExchange.Add(Ingratel);
        }


        /// <summary>
        /// 分配参与投注人的中奖金额
        /// </summary>
        /// <param name="userBuyInfo">Model.LotteryChipped model</param>
        private static void distributionUserMoney(Model.LotteryChipped model)
        {
            if (model != null && model.IsWin == true)
            {
                DataTable chippedUser = BLL.LotteryChippedUser.GetPageListBysql("select * from LotteryChippedUser where Flag=0 and LotteryChippedID=" + model.id);
                foreach (DataRow dr in chippedUser.Rows)
                {
                    //更新参与合买人的投注记录
                    Model.LotteryChippedUser LotteryChippedUser = BLL.LotteryChippedUser.GetModel(long.Parse(dr["id"].ToString()));
                    if (LotteryChippedUser != null)
                    {
                        LotteryChippedUser.IsWin = true;
                        LotteryChippedUser.WinMoney = model.WinMoney * decimal.Parse(LotteryChippedUser.MySubRate);
                        LotteryChippedUser.Flag = true;
                        BLL.LotteryChippedUser.Update(LotteryChippedUser);
                    }
                    //更新参与合买人的账户
                    Model.UsersAccount userChipped = BLL.UsersAccount.GetModelByuser_id(long.Parse(dr["UserID"].ToString()));
                    if (userChipped != null)
                    {
                        userChipped.total = userChipped.total + LotteryChippedUser.WinMoney;
                        userChipped.winTotal = userChipped.winTotal + LotteryChippedUser.WinMoney;
                        BLL.UsersAccount.Update(userChipped);
                    }
                }
                //更新发布合买人的账户
                Model.UsersAccount faburenChipped = BLL.UsersAccount.GetModelByuser_id(long.Parse(model.UserID.ToString()));
                if (faburenChipped != null)
                {
                    decimal userMoney = (decimal)model.MySub / (decimal)model.LotteryMoney * (decimal)model.WinMoney;
                    faburenChipped.total = faburenChipped.total + userMoney;
                    faburenChipped.winTotal = faburenChipped.winTotal + userMoney;
                    BLL.UsersAccount.Update(faburenChipped);
                }
            }
        }
        /// <summary>
        /// 遍历中奖情况
        /// </summary>
        /// <param name="lotteryQs">彩票期数</param>
        /// <param name="lotteryNumber">开奖号码</param>
        /// <param name="lotteryType">彩票类型</param>
        /// <returns>成功 失败</returns>
        public static bool TraverseTheWinning(string lotteryQs, string lotteryNumber, int lotteryType)
        {
            List<Model.LotteryChipped> userBuyInfo = new List<Model.LotteryChipped>();
            int totalcount = 0;
            string sql = "Flag=0 and State=1 and LotteryYE=0 and ProjectStatus=2 and LotteryType=" + lotteryType + " and  LotteryOpenTime=" + lotteryQs;
            userBuyInfo = BLL.LotteryChipped.GetPageListBysql(0, int.MaxValue, sql, out totalcount);
            if (userBuyInfo != null)
            {
                for (int i = 0; i < userBuyInfo.Count; i++)
                {
                    //双色球
                    if (lotteryType == 1)
                    {
                        int[] level = calculateRed(lotteryNumber, userBuyInfo[i].LotteryNo);
                        //更新数据库
                        updateUserAccoutBySSQ(level, userBuyInfo[i].id);
                        addWinInfo(level, lotteryType, lotteryQs, userBuyInfo[i].id);

                    }//大乐透
                    else if (lotteryType == 2)
                    {
                        int[] level = calculateDLT(lotteryNumber, userBuyInfo[i].LotteryNo);
                        //更新数据库
                        updateUserAccoutByDLT(level, userBuyInfo[i].id);
                        addWinInfo(level, lotteryType, lotteryQs, userBuyInfo[i].id);

                    }//排列三
                    else if (lotteryType == 3)
                    {
                        string[] userLotteryNo = userBuyInfo[i].LotteryNo.Split(',');
                        string levestr = "";
                        for (int n = 0; n < userLotteryNo.Length; n++)
                        {
                            int level = calculatePLS(lotteryNumber, userLotteryNo[n]);
                            levestr += "," + level.ToString();
                        }
                        levestr = levestr.TrimStart(',');
                        //更新数据库
                        updateUserAccoutByPLS(levestr, userBuyInfo[i].id);

                    }//排列五
                    else if (lotteryType == 4)
                    {
                        calculatePLW(lotteryNumber, userBuyInfo[i].LotteryNo, userBuyInfo[i].id);

                    }//福彩3D
                    else if (lotteryType == 5)
                    {
                        //更新数据库(string winSSQStr, string SSQStr, int userID, int LotteryChippedID, int fcType, int fcTypeNext)
                        calculateFC(lotteryNumber, userBuyInfo[i].LotteryNo, userBuyInfo[i].UserID, userBuyInfo[i].id, userBuyInfo[i].fcType, userBuyInfo[i].fcTypeNext);

                    }//七星彩
                    else if (lotteryType == 6)
                    {
                        string[] userLotteryNo = userBuyInfo[i].LotteryNo.Split(',');
                        string levestr = "";
                        for (int n = 0; n < userLotteryNo.Length; n++)
                        {
                            int level = calculateQXC(lotteryNumber, userLotteryNo[n]);
                            levestr += "," + level.ToString();
                        }
                        levestr = levestr.TrimStart(',');
                        //更新数据库
                        updateUserAccoutByQXC(levestr, userBuyInfo[i].id);

                    }//七乐彩
                    else if (lotteryType == 7)
                    {
                        string[] userLotteryNo = userBuyInfo[i].LotteryNo.Split(',');
                        string levestr = "";
                        for (int n = 0; n < userLotteryNo.Length; n++)
                        {
                            int level = calculateQLC(lotteryNumber, userLotteryNo[n]);
                            levestr += "," + level.ToString();
                        }
                        levestr = levestr.TrimStart(',');
                        //更新数据库
                        updateUserAccoutByQLC(levestr, userBuyInfo[i].id);

                    }
                }
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 双色球中奖
        /// </summary>
        /// <param name="winSSQStr">开奖号码</param>
        /// <param name="SSQStr">用户购买的号码</param>
        /// <returns>等级</returns>
        private static int[] calculateRed(string winSSQStr, string SSQStr)
        {
            int dmRedCount = 0;
            int tmRedCount = 0;
            int dtBlueCount = 0;
            int[] level = new int[6];
            //中奖号
            string[] winSSQList = winSSQStr.Split('+');
            string[] winRed = winSSQList[0].Split(',');
            string[] winBlue = winSSQList[1].Split(',');
            //用户号码
            //SSQStr = SSQStr.Replace("$","*");
            string[] SSQ = SSQStr.Split(',');
            for (int n = 0; n < SSQ.Length; n++)
            {
                if (SSQ[n].Contains("$"))
                {
                    string[] SSQList = SSQ[n].Split('+');
                    string[] userRed = SSQList[0].Split('$');
                    string[] userDm = userRed[0].Split('*');
                    string[] userTm = userRed[1].Split('*');
                    string[] UserBlue = SSQList[1].Split('*');
                    for (int i = 0; i < winRed.Length; i++)
                    {
                        for (int j = 0; j < userDm.Length; j++)
                        {
                            if (int.Parse(winRed[i]) == int.Parse(userDm[j]))
                            {
                                dmRedCount++;
                                break;
                            }
                        }
                    }
                    for (int i = 0; i < winRed.Length; i++)
                    {
                        for (int j = 0; j < userTm.Length; j++)
                        {
                            if (int.Parse(winRed[i]) == int.Parse(userTm[j]))
                            {
                                tmRedCount++;
                                break;
                            }
                        }
                    }
                    //比对蓝球
                    for (int i = 0; i < winBlue.Length; i++)
                    {
                        for (int j = 0; j < UserBlue.Length; j++)
                        {
                            if (int.Parse(winBlue[i]) == int.Parse(UserBlue[j]))
                            {
                                dtBlueCount++;
                                break;
                            }
                        }
                    }
                    int b = userTm.Length;
                    int e = userDm.Length;
                    int r = UserBlue.Length;
                    int g = dmRedCount;
                    int s = tmRedCount;
                    int o = dtBlueCount;
                    var u = s <= 6 - e ? s : 6 - e;
                    int[] a = new int[10];
                    for (var f = 0; f <= u; f++)
                    {
                        a[f] = g + f;
                    }
                    int c = 0;
                    if (o == 1)
                    {
                        for (var f = 0; f <= u; f++)
                        {
                            c = Rank(a[f], 0);
                            if (c != -1)
                            {
                                level[c] += Ccombo(b - s, 6 - e - f) * (r - 1) * Ccombo(s, f);
                                c = Rank(a[f], 1);
                                level[c] += Ccombo(b - s, 6 - e - f) * Ccombo(s, f);
                            }
                        }
                    }
                    if (o == 0)
                    {
                        for (var f = 0; f <= u; f++)
                        {
                            c = Rank(a[f], 0);
                            if (c != -1)
                            {
                                level[c] += Ccombo(b - s, 6 - e - f) * r * Ccombo(s, f);
                            }
                        }
                    }
                    //level = l[0].ToString() + "," + l[1] + "," + l[2] + "," + l[3] + "," + l[4]+ "," + l[5];
                    //oneZS = l[0]; twoZS = l[1]; threeZS = l[2]; fourZS = l[3]; fiveZS = l[4]; six = l[5];
                }
                else
                {
                    string[] SSQList = SSQ[n].Split('+');
                    string[] UserRed = SSQList[0].Split('*');
                    string[] UserBlue = SSQList[1].Split('*');

                    int redCount = 0;
                    int blueCount = 0;
                    //比对红球
                    for (int m = 0; m < winRed.Length; m++)
                    {
                        for (int j = 0; j < UserRed.Length; j++)
                        {
                            if (int.Parse(winRed[m]) == int.Parse(UserRed[j]))
                            {
                                redCount++;
                                break;
                            }
                        }
                    }
                    //比对蓝球
                    for (int t = 0; t < winBlue.Length; t++)
                    {
                        for (int j = 0; j < UserBlue.Length; j++)
                        {
                            if (int.Parse(winBlue[t]) == int.Parse(UserBlue[j]))
                            {
                                blueCount++;
                                break;
                            }
                        }
                    }
                    int u = UserRed.Length;
                    int r = UserBlue.Length;
                    int i = redCount;
                    int s = blueCount;
                    if (i < 3)
                    {
                        if (blueCount > 0)
                        {
                            level[5] += combo(u, 6);
                        }
                    }
                    else if (i == 3)
                    {
                        if (blueCount > 0)
                        {
                            level[5] += combo(u - i, 4) * combo(i, 2);
                            level[5] += combo(u - i, 5) * combo(i, 1);
                            level[5] += combo(u - i, 6);
                            level[4] += combo(u - i, 3);
                        }
                    }
                    else if (i == 4)
                    {
                        if (s > 0)
                        {
                            level[5] += combo(u - i, 6);
                            level[5] += combo(u - i, 5) * combo(i, 1);
                            level[5] += combo(u - i, 4) * combo(i, 2);
                            level[4] += combo(u - i, 3) * combo(i, 3);
                            level[4] += combo(u - i, 2) * combo(i, 4) * (r - 1);
                            level[3] += combo(u - i, 2);
                        }
                        else
                        {
                            level[4] += combo(u - i, 2) * r;
                        }
                    }
                    else if (i == 5)
                    {
                        if (s > 0)
                        {
                            level[5] += combo(u - i, 6);
                            level[5] += combo(u - i, 5) * combo(i, 1);
                            level[5] += combo(u - i, 4) * combo(i, 2);
                            level[4] += combo(u - i, 3) * combo(i, 3);
                            level[4] += combo(u - i, 2) * combo(i, 4) * (r - 1);
                            level[3] += combo(u - i, 2) * combo(i, 4);
                            level[3] += combo(u - i, 1) * combo(i, 5) * (r - 1);
                            level[2] += combo(u - i, 1);
                        }
                        else
                        {
                            level[4] += combo(u - i, 2) * combo(i, 4) * r;
                            level[3] += combo(u - i, 1) * combo(i, 5) * r;

                        }
                    }
                    else if (i == 6)
                    {
                        if (s > 0)
                        {
                            level[5] += combo(u - i, 6);
                            level[5] += combo(u - i, 5) * combo(i, 1);
                            level[5] += combo(u - i, 4) * combo(i, 2);
                            level[4] += combo(u - i, 3) * combo(i, 3);
                            level[4] += combo(u - i, 2) * combo(i, 4) * (r - 1);
                            level[3] += combo(u - i, 2) * combo(i, 4);
                            level[3] += combo(u - i, 1) * combo(i, 5) * (r - 1);
                            level[2] += combo(u - i, 1) * combo(i, 5);
                            level[1] += r - 1;
                            level[0]++;
                        }
                        else
                        {
                            level[4] += combo(u - i, 2) * combo(i, 4) * r;
                            level[3] += combo(u - i, 1) * combo(i, 5) * r;
                            level[1] += r;
                        }
                    }
                    //level = o[0].ToString() + "," + o[1] + "," + o[2] + "," + o[3] + "," + o[4] + "," + o[5];
                }
            }
            return level;
        }
        /// <summary>
        /// 双色球更新中奖信息
        /// </summary>
        /// <param name="level">中奖等级</param>
        /// <param name="userID">用户id</param>
        /// <param name="LotteryChippedID">购买彩票的id</param>
        private static void updateUserAccoutBySSQ(int[] level, int LotteryChippedID)
        {
            decimal winMoney = 0;
            bool isWin = true;
            int maxLevel = -1;
            string sql = string.Format("SELECT top 1 * FROM LotteryAnnouncement WHERE LotteryType={0} and LotteryQS=(select LotteryOpenTime from LotteryChipped where id={1})", 1, LotteryChippedID);
            la = BLL.LotteryAnnouncement.GetModelBySql(sql);
            if (la != null)
            {
                oneMoney = la.oneMoney;
                twoMoney = la.twoMoney;
            }
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            //string[] levelList = level.Split(',');
            for (int n = 0; n < level.Length; n++)
            {
                if (level[n] != 0)
                {
                    maxLevel = n + 1;
                }
                if (n == 0)
                {
                    winMoney += oneMoney * level[0];
                }
                else if (n == 1)
                {
                    winMoney += twoMoney * level[1];
                }
                else if (n == 2)
                {
                    winMoney += 3000 * level[2];
                }
                else if (n == 3)
                {
                    winMoney += 200 * level[3];
                }
                else if (n == 4)
                {
                    winMoney += 10 * level[4];
                }
                else if (n == 5)
                {
                    winMoney += 5 * level[5];
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
            }
            else
            {
                isWin = false;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney * model.LotteryMultiple;
            model.Flag = true;
            sumWinMoney = winMoney;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }

        }
        /// <summary>
        /// 大乐透中奖
        /// </summary>
        /// <param name="winSSQStr">开奖号码</param>
        /// <param name="SSQStr">用户购买的号码</param>
        /// <returns>等级</returns>
        private static int[] calculateDLT(string winSSQStr, string SSQStr)
        {

            int dmRedCount = 0;
            int tmRedCount = 0;
            int dmBlueCount = 0;
            int tmBlueCount = 0;
            string[] dmUserRed = null;
            string[] tmUserRed = null;
            string[] dmUserBlue = null;
            string[] tmUserBlue = null;
            int[] level = new int[6];
            //中奖号
            string[] winSSQList = winSSQStr.Split('+');
            string[] winRed = winSSQList[0].Split(',');
            string[] winBlue = winSSQList[1].Split(',');
            //用户号码
            //SSQStr = SSQStr.Replace("$","*");
            string[] DLT = SSQStr.Split(',');
            for (int n = 0; n < DLT.Length; n++)
            {
                if (DLT[n].Contains("$"))
                {
                    string[] DLTList = DLT[n].Split('+');
                    if (DLTList[0].Contains("$"))
                    {
                        dmUserRed = DLTList[0].Split('$')[0].Split('*');
                        tmUserRed = DLTList[0].Split('$')[1].Split('*');
                        for (int i = 0; i < winRed.Length; i++)
                        {
                            for (int j = 0; j < dmUserRed.Length; j++)
                            {
                                if (int.Parse(winRed[i]) == int.Parse(dmUserRed[j]))
                                {
                                    dmRedCount++;
                                    break;
                                }
                            }
                        }
                        for (int i = 0; i < winRed.Length; i++)
                        {
                            for (int j = 0; j < tmUserRed.Length; j++)
                            {
                                if (int.Parse(winRed[i]) == int.Parse(tmUserRed[j]))
                                {
                                    tmRedCount++;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        string[] UserRed = DLTList[0].Split('*');
                        for (int i = 0; i < winRed.Length; i++)
                        {
                            for (int j = 0; j < UserRed.Length; j++)
                            {
                                if (int.Parse(winRed[i]) == int.Parse(UserRed[j]))
                                {
                                    dmRedCount++;
                                    break;
                                }
                            }
                        }
                        tmRedCount = 0;
                    }
                    if (DLTList[1].Contains("$"))
                    {
                        dmUserBlue = DLTList[1].Split('$')[0].Split('*');
                        tmUserBlue = DLTList[1].Split('$')[1].Split('*');
                        for (int i = 0; i < winBlue.Length; i++)
                        {
                            for (int j = 0; j < dmUserBlue.Length; j++)
                            {
                                if (int.Parse(winBlue[i]) == int.Parse(dmUserBlue[j]))
                                {
                                    dmBlueCount++;
                                    break;
                                }
                            }
                        }
                        for (int i = 0; i < winBlue.Length; i++)
                        {
                            for (int j = 0; j < tmUserBlue.Length; j++)
                            {
                                if (int.Parse(winBlue[i]) == int.Parse(tmUserBlue[j]))
                                {
                                    tmBlueCount++;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        string[] userBlue = DLTList[1].Split('*');
                        for (int i = 0; i < winRed.Length; i++)
                        {
                            for (int j = 0; j < userBlue.Length; j++)
                            {
                                if (int.Parse(winBlue[i]) == int.Parse(userBlue[j]))
                                {
                                    dmBlueCount++;
                                    break;
                                }
                            }
                        }
                        tmBlueCount = 0;
                    }
                    int r = dmUserRed == null ? 5 : dmUserRed.Length;
                    int m = tmUserRed == null ? 0 : tmUserRed.Length;
                    int s = dmUserBlue == null ? 2 : dmUserBlue.Length;
                    int o = dmUserBlue == null ? 0 : tmUserBlue.Length;
                    int u = dmRedCount;
                    int a = tmRedCount;
                    int f = dmBlueCount;
                    int l = tmBlueCount;
                    int c = a <= 5 - r ? a : 5 - r;
                    int h = l <= 2 - s ? l : 2 - s;
                    int[] p = new int[6];
                    int[] d = new int[6];
                    for (var v = 0; v <= c; v++) p[v] = u + v;
                    for (int v = 0; v <= h; v++) d[v] = f + v;
                    int g = 0;
                    for (int v = 0; v <= c; v++)
                    {
                        for (var y = 0; y <= h; y++)
                        {
                            g = Rankx(p[v], d[y]);
                            if (g != -1)
                            {
                                level[g] += Ccombo(m - a, 5 - r - v) * Ccombo(a, v) * Ccombo(o - l, 2 - s - y) * Ccombo(l, y);
                            }
                        }
                    }
                    //string[] userRed = DLTList[0].Split('$');
                    //string[] userDm = userRed[0].Split('*');
                    //string[] userTm = userRed[1].Split('*');
                    //string[] UserBlue = DLTList[1].Split('*');
                    ////比对蓝球
                    //for (int i = 0; i < winBlue.Length; i++)
                    //{
                    //    for (int j = 0; j < UserBlue.Length; j++)
                    //    {
                    //        if (int.Parse(winBlue[i]) == int.Parse(UserBlue[j]))
                    //        {
                    //            dmBlueCount++;
                    //            break;
                    //        }
                    //    }
                    //}
                }
                else
                {
                    string[] SSQList = DLT[n].Split('+');
                    string[] UserRed = SSQList[0].Split('*');
                    string[] UserBlue = SSQList[1].Split('*');

                    int redCount = 0;
                    int blueCount = 0;
                    //比对红球
                    for (int m = 0; m < winRed.Length; m++)
                    {
                        for (int j = 0; j < UserRed.Length; j++)
                        {
                            if (int.Parse(winRed[m]) == int.Parse(UserRed[j]))
                            {
                                redCount++;
                                break;
                            }
                        }
                    }
                    //比对蓝球
                    for (int m = 0; m < winBlue.Length; m++)
                    {
                        for (int j = 0; j < UserBlue.Length; j++)
                        {
                            if (int.Parse(winBlue[m]) == int.Parse(UserBlue[j]))
                            {
                                blueCount++;
                                break;
                            }
                        }
                    }
                    int r = UserRed.Length;
                    int i = UserBlue.Length;
                    int s = redCount;
                    int o = blueCount;

                    for (var u = 0; u <= s; u++)
                        for (var a = 0; a <= o; a++)
                        {
                            int f = Rankx(u, a);
                            if (f != -1)
                            {
                                level[f] += combo(s, u) * combo(r - s, 5 - u) * combo(i - o, 2 - a) * combo(o, a);
                            }
                        }
                }
            }
            return level;
        }
        /// <summary>
        /// 大乐透更新中奖信息
        /// </summary>
        /// <param name="level">中奖等级</param>
        /// <param name="userID">用户id</param>
        /// <param name="LotteryChippedID">购买彩票的id</param>
        private static void updateUserAccoutByDLT(int[] level, int LotteryChippedID)
        {
            decimal winMoney = 0;
            bool isWin = true;
            int maxLevel = -1;
            string sql = string.Format("SELECT top 1 * FROM LotteryAnnouncement WHERE LotteryType={0} and LotteryQS=(select LotteryOpenTime from LotteryChipped where id={1})", 2, LotteryChippedID);
            la = BLL.LotteryAnnouncement.GetModelBySql(sql);
            if (la != null)
            {
                oneMoney = la.oneMoney;
                twoMoney = la.twoMoney;
                threeMoney = la.threeMoney;
            }
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            for (int n = 0; n < level.Length; n++)
            {
                if (level[n] != 0)
                {
                    maxLevel = n + 1;
                }
                if (n == 0)
                {
                    winMoney += oneMoney * level[0] * model.LotteryMultiple;
                }
                else if (n == 1)
                {
                    winMoney += twoMoney * level[1] * model.LotteryMultiple;
                }
                else if (n == 2)
                {
                    winMoney += threeMoney * level[2] * model.LotteryMultiple;
                }
                else if (n == 3)
                {
                    winMoney += 200 * model.LotteryMultiple * level[3];
                }
                else if (n == 4)
                {
                    winMoney += 10 * model.LotteryMultiple * level[4];
                }
                else if (n == 5)
                {
                    winMoney += 5 * model.LotteryMultiple * level[5];
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
            }
            else
            {
                isWin = false;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;
            sumWinMoney = winMoney;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
        }

        /// <summary>
        /// 排列五中奖并更新数据库
        /// </summary>
        /// <param name="winSSQStr">开奖号码</param>
        /// <param name="SSQStr">用户购买的号码</param>
        /// <returns>等级</returns>
        private static void calculatePLW(string winSSQStr, string SSQStr, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            //中奖号
            string[] winSSQList = winSSQStr.Split(',');
            //用户号码
            string[] SSQList = SSQStr.Split(',');
            string level = "";
            for (int n = 0; n < SSQList.Length; n++)
            {
                string[] plwList = SSQList[n].Split('*');
                int Count = 0;
                //比对红球
                for (int i = 0; i < winSSQList.Length; i++)
                {
                    int index = plwList[i].IndexOf(winSSQList[i]);
                    if (index > -1)
                    {
                        Count++;
                    }
                }
                if (Count == 5)
                {
                    level += ",1";
                }
                else
                {
                    level += ",-1";
                }
            }
            decimal winMoney = 0;
            bool isWin = false;
            int maxLevel = -1;
            string[] levelList = level.TrimStart(',').Split(',');
            for (int n = 0; n < levelList.Length; n++)
            {
                if (maxLevel < int.Parse(levelList[n]))
                {
                    maxLevel = int.Parse(levelList[n]);
                }
                if (int.Parse(levelList[n]) == 1)
                {
                    isWin = true;
                    winMoney += 100000 * model.LotteryMultiple;
                }
                else
                {
                    winMoney += 0;
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
            }
            //更新数据库 
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
        }

        /// <summary>
        /// 七乐彩中奖
        /// </summary>
        /// <param name="winSSQStr">开奖号码</param>
        /// <param name="SSQStr">用户购买的号码</param>
        /// <returns>等级</returns>
        private static int calculateQLC(string winSSQStr, string SSQStr)
        {
            //中奖号
            string[] winSSQList = winSSQStr.Split('+');
            string[] winBall = winSSQList[0].Split(',');
            string[] specialBall = null;

            if (winSSQList.Length > 1)
            {
                specialBall = winSSQList[1].Split(',');
            }
            //用户号码 
            SSQStr = SSQStr.Replace("$", "*");
            string[] userBall = SSQStr.Split('*');
            int level = -1;
            int ballCount = 0;
            int specialBallCount = 0;
            //比对中奖号码
            for (int i = 0; i < winBall.Length; i++)
            {
                for (int j = 0; j < userBall.Length; j++)
                {
                    if (winBall[i].Equals(userBall[j]))
                    {
                        ballCount++;
                        break;
                    }
                }
            }
            //比对特殊号码
            if (specialBall != null)
            {
                for (int i = 0; i < specialBall.Length; i++)
                {
                    for (int j = 0; j < userBall.Length; j++)
                    {
                        if (specialBall[i].Equals(userBall[j]))
                        {
                            specialBallCount++;
                            break;
                        }
                    }
                }
            }
            if (ballCount == 7)
            {
                level = 1;
            }
            else if (ballCount == 6 && specialBallCount == 1)
            {
                level = 2;
            }
            else if (ballCount == 6)
            {
                level = 3;
            }
            else if (ballCount == 5 && specialBallCount == 1)
            {
                level = 4;
            }
            else if (ballCount == 5)
            {
                level = 5;
            }
            else if (ballCount == 4 && specialBallCount == 1)
            {
                level = 6;
            }
            else if (ballCount == 4)
            {
                level = 7;
            }
            else
            {
                level = -1;
            }
            return level;
        }
        /// <summary>
        /// 七乐彩更新中奖信息
        /// </summary>
        /// <param name="level">中奖等级</param>
        /// <param name="userID">用户id</param>
        /// <param name="LotteryChippedID">购买彩票的id</param>
        private static void updateUserAccoutByQLC(string level, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            decimal winMoney = 0;
            bool isWin = true;
            int maxLevel = -1;
            string[] levelList = level.Split(',');
            for (int n = 0; n < levelList.Length; n++)
            {
                if (maxLevel < int.Parse(levelList[n]))
                {
                    maxLevel = int.Parse(levelList[n]);
                }
                if (int.Parse(levelList[n]) == 1)
                {
                    winMoney += 0;
                }
                else if (int.Parse(levelList[n]) == 2)
                {
                    winMoney += 0;
                }
                else if (int.Parse(levelList[n]) == 3)
                {
                    winMoney += 0;
                }
                else if (int.Parse(levelList[n]) == 4)
                {
                    winMoney += 200 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 5)
                {
                    winMoney += 50 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 6)
                {
                    winMoney += 10 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 7)
                {
                    winMoney += 5 * model.LotteryMultiple;
                }
                else
                {
                    isWin = false;
                    winMoney += 0;
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
        }
        /// <summary>
        /// 七星彩中奖
        /// </summary>
        /// <param name="winSSQStr">开奖号码</param>
        /// <param name="SSQStr">用户购买的号码</param>
        /// <returns>等级</returns>
        private static int calculateQXC(string winSSQStr, string SSQStr)
        {
            //中奖号
            string[] winSSQList = winSSQStr.Split(',');
            //用户号码
            string[] SSQList = SSQStr.Split('*');

            int level = -1;
            bool one = false;
            bool two = false;
            bool three = false;
            bool four = false;
            bool five = false;
            bool six = false;
            bool seven = false;
            //比对中奖位置是否中奖号码
            for (int i = 0; i < winSSQList.Length; i++)
            {
                int index = SSQList[i].IndexOf(winSSQList[i]);
                if (index > -1)
                {
                    if (i == 0) { one = true; }
                    else if (i == 1) { two = true; }
                    else if (i == 2) { three = true; }
                    else if (i == 3) { four = true; }
                    else if (i == 4) { five = true; }
                    else if (i == 5) { six = true; }
                    else if (i == 6) { seven = true; }
                }
            }
            if (one && two && three && four && five && six && seven)
            {
                level = 1;
            }
            else if ((one && two && three && four && five && six) || (two && three && four && five && six && seven))
            {
                level = 2;
            }
            else if ((one && two && three && four && five) || (two && three && four && five && six) || (three && four && five && six && seven))
            {
                level = 3;
            }
            else if ((one && two && three && four) || (two && three && four && five) || (three && four && five && six) || (four && five && six && seven))
            {
                level = 4;
            }
            else if ((one && two && three) || (two && three && four) || (three && four && five) || (four && five && six) || (five && six && seven))
            {
                level = 5;
            }
            else if ((one && two) || (two && three) || (three && four) || (four && five) || (five && six) || (seven && six))
            {
                level = 6;
            }
            return level;
        }
        /// <summary>
        /// 七星彩更新中奖信息
        /// </summary>
        /// <param name="level">中奖等级</param>
        /// <param name="userID">用户id</param>
        /// <param name="LotteryChippedID">购买彩票的id</param>
        private static void updateUserAccoutByQXC(string level, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            decimal winMoney = 0;
            bool isWin = true;
            int maxLevel = -1;
            string[] levelList = level.Split(',');
            for (int n = 0; n < levelList.Length; n++)
            {
                if (maxLevel < int.Parse(levelList[n]))
                {
                    maxLevel = int.Parse(levelList[n]);
                }
                if (int.Parse(levelList[n]) == 1)
                {
                    winMoney += 0;
                }
                else if (int.Parse(levelList[n]) == 2)
                {
                    winMoney += 0;
                }
                else if (int.Parse(levelList[n]) == 3)
                {
                    winMoney += 1800 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 4)
                {
                    winMoney += 300 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 5)
                {
                    winMoney += 20 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 6)
                {
                    winMoney += 5 * model.LotteryMultiple;
                }
                else
                {
                    isWin = false;
                    winMoney += 0;
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
        }
        /// <summary>
        /// 排列三中奖
        /// </summary>
        /// <param name="winSSQStr">开奖号码</param>
        /// <param name="SSQStr">用户购买的号码</param>
        /// <returns>等级</returns>
        private static int calculatePLS(string winSSQStr, string SSQStr)
        {
            List<string> lastList = new List<string>();
            //中奖号
            string[] winSSQList = winSSQStr.Split(',');
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (i != j && i != k && j != k)
                        {
                            string listStr = winSSQList[i] + "," + winSSQList[j] + "," + winSSQList[k];
                            lastList.Add(listStr);
                        }
                    }
                }
            }
            //用户号码
            string[] SSQList = SSQStr.Split('*');

            int level = -1;
            int Count = 0;
            //直选 	与开奖号相同，顺序一致 一等奖
            for (int i = 0; i < winSSQList.Length; i++)
            {
                int index = SSQList[i].IndexOf(winSSQList[i]);
                if (index > -1)
                {
                    Count++;
                }
            }

            if (Count == 3)
            {
                level = 1;
                return level;
            }
            //组三
            if ((winSSQList[0] == winSSQList[1] && winSSQList[0] != winSSQList[2])
                || (winSSQList[0] != winSSQList[1] && winSSQList[1] == winSSQList[2])
                || (winSSQList[0] == winSSQList[2] && winSSQList[0] != winSSQList[1]))
            {
                for (int i = 0; i < lastList.Count; i++)
                {
                    int countFlag = 0;
                    string[] flagList = lastList[i].Split(',');
                    for (int j = 0; j < flagList.Length; j++)
                    {
                        int index = SSQList[j].IndexOf(flagList[j]);
                        if (index > -1)
                        {
                            countFlag++;
                        }
                        if (countFlag == 3)
                        {
                            level = 2;
                            return level;
                        }
                    }
                }
            }
            //组六
            if (winSSQList[0] != winSSQList[1] && winSSQList[0] != winSSQList[2]
                && winSSQList[1] != winSSQList[2] && (int.Parse(winSSQList[0]) + 2) != int.Parse(winSSQList[2]))
            {
                for (int i = 0; i < lastList.Count; i++)
                {
                    int countFlag = 0;
                    string[] flagList = lastList[i].Split(',');
                    for (int j = 0; j < flagList.Length; j++)
                    {
                        int index = SSQList[j].IndexOf(flagList[j]);
                        if (index > -1)
                        {
                            countFlag++;
                        }
                        if (countFlag == 3)
                        {
                            level = 3;
                            return level;
                        }
                    }
                }
            }
            return level;
        }
        /// <summary>
        /// 排列三更新中奖信息
        /// </summary>
        /// <param name="level">中奖等级</param>
        /// <param name="userID">用户id</param>
        /// <param name="LotteryChippedID">购买彩票的id</param>
        private static void updateUserAccoutByPLS(string level, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            decimal winMoney = 0;
            bool isWin = true;
            int maxLevel = -1;
            string[] levelList = level.Split(',');
            for (int n = 0; n < levelList.Length; n++)
            {
                if (maxLevel < int.Parse(levelList[n]))
                {
                    maxLevel = int.Parse(levelList[n]);
                }
                if (int.Parse(levelList[n]) == 1)
                {
                    winMoney += 1040 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 2)
                {
                    winMoney += 346 * model.LotteryMultiple;
                }
                else if (int.Parse(levelList[n]) == 3)
                {
                    winMoney += 173 * model.LotteryMultiple;
                }
                else
                {
                    isWin = false;
                    winMoney += 0;
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
        }
        /// <summary>
        /// 福彩
        /// </summary>
        /// <param name="winSSQStr">开奖号</param>
        /// <param name="SSQStr">用户号码</param>
        /// <param name="SSQStr">用户购买的类型1:直选, 2:通选,3:组三,4:组六,5:和数,6:包选，7:1D，8:2D,9:大小奇偶,10:拖拉机，11:猜三同 </param>
        public static void calculateFC(string winSSQStr, string SSQStr, int userID, int LotteryChippedID, int fcType, int fcTypeNext)
        {   //中奖号
            string[] winSSQList = winSSQStr.Split(',');
            //用户号码
            string[] SSQList = SSQStr.Split(',');
            //直选
            if (fcType == 1)
            {
                ZX(winSSQList, SSQList, LotteryChippedID);
            }
            //通选
            else if (fcType == 2)
            {
                TX(winSSQList, SSQList, LotteryChippedID);
            }
            //组三
            else if (fcType == 3)
            {
                ZS(winSSQStr, SSQList, LotteryChippedID);
            }
            //组六
            else if (fcType == 4)
            {
                ZL(winSSQStr, SSQList, LotteryChippedID);
            }
            //和数
            else if (fcType == 5)
            {
                HS(winSSQList, SSQStr, LotteryChippedID);
            }
            //包选
            else if (fcType == 6)
            {
                BX(winSSQList, SSQList, LotteryChippedID);
            }
            //1D
            else if (fcType == 7)
            {
                Do1D(winSSQList, SSQList, LotteryChippedID);
            }
            //2D
            else if (fcType == 8)
            {
                Do2D(winSSQList, SSQList, LotteryChippedID);
            }
            //大小奇偶
            else if (fcType == 9)
            {
                CST(winSSQList, LotteryChippedID, fcType, fcTypeNext);
            }
            //拖拉机
            else if (fcType == 10)
            {
                CST(winSSQList, LotteryChippedID, fcType, fcTypeNext);
            }
            //猜三同
            else if (fcType == 11)
            {
                CST(winSSQList, LotteryChippedID, fcType, fcTypeNext);
            }
        }
        /// <summary>
        /// 直选
        /// </summary>
        public static void ZX(string[] winSSQList, string[] SSQList, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            int maxLevel = -1;
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            for (int n = 0; n < SSQList.Length; n++)
            {
                int count = 0;
                string[] fcList = SSQList[n].Split('*');
                for (int i = 0; i < winSSQList.Length; i++)
                {
                    int index = fcList[i].IndexOf(winSSQList[i]);
                    if (index > -1)
                    {
                        count++;
                    }
                }
                if (count == 3)
                {
                    winMoney += 1040 * model.LotteryMultiple;
                    level[0]++;
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
                level[1] = level[2] = level[3] = level[4] = level[5] = 0;
                maxLevel = 1;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void TX(string[] winSSQList, string[] SSQList, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            int maxLevel = -1;
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            for (int n = 0; n < SSQList.Length; n++)
            {
                int count = 0;
                string[] fcList = SSQList[n].Split('*');
                for (int i = 0; i < winSSQList.Length; i++)
                {
                    int index = fcList[i].IndexOf(winSSQList[i]);
                    if (index > -1)
                    {
                        count++;
                    }
                }
                if (count == 3)
                {
                    isWin = true;
                    winMoney += 470 * model.LotteryMultiple;
                    level[5]++;
                }
                else if (count == 2)
                {
                    isWin = true;
                    winMoney += 21 * model.LotteryMultiple;
                    level[5]++;
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
                level[0] = level[2] = level[3] = level[4] = level[1] = 0;
                maxLevel = 2;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void ZS(string winSSQStr, string[] SSQList, int LotteryChippedID)
        {
            int count = 0;
            int maxLevel = -1;
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            List<string> lastList = getWinNoSort(winSSQStr);
            string[] winSSQList = winSSQStr.Split(',');
            if ((winSSQList[0] == winSSQList[1] && winSSQList[0] != winSSQList[2])
                || (winSSQList[0] != winSSQList[1] && winSSQList[1] == winSSQList[2])
                || (winSSQList[0] == winSSQList[2] && winSSQList[0] != winSSQList[1]))
            {
                for (int n = 0; n < SSQList.Length; n++)
                {
                    string[] fcList = SSQList[n].Split('*');
                    for (int i = 0; i < lastList.Count; i++)
                    {
                        int countFlag = 0;
                        string[] flagList = lastList[i].Split(',');
                        for (int j = 0; j < flagList.Length; j++)
                        {
                            int index = fcList[j].IndexOf(flagList[j]);
                            if (index > -1)
                            {
                                countFlag++;
                            }
                            if (countFlag == 3)
                            {
                                isWin = true;
                                winMoney += 346 * model.LotteryMultiple;
                                count++;
                            }
                        }
                    }
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
                level[1] = count / 2;
                level[0] = level[2] = level[3] = level[4] = level[5] = 0;
                maxLevel = 3;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney / 2;
            model.Flag = true;
            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney / 2;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void ZL(string winSSQStr, string[] SSQList, int LotteryChippedID)
        {
            int maxLevel = -1;
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            List<string> lastList = getWinNoSort(winSSQStr);
            string[] winSSQList = winSSQStr.Split(',');
            Array.Sort(winSSQList);
            if (winSSQList[0] != winSSQList[1] && winSSQList[0] != winSSQList[2]
                && winSSQList[1] != winSSQList[2] && (int.Parse(winSSQList[0]) + 2) != int.Parse(winSSQList[2]))
            {
                for (int n = 0; n < SSQList.Length; n++)
                {
                    string[] fcList = SSQList[n].Split('*');

                    for (int i = 0; i < lastList.Count; i++)
                    {
                        int countFlag = 0;
                        string[] flagList = lastList[i].Split(',');
                        for (int j = 0; j < flagList.Length; j++)
                        {
                            int index = fcList[j].IndexOf(flagList[j]);
                            if (index > -1)
                            {
                                countFlag++;
                            }
                            if (countFlag == 3)
                            {
                                winMoney += 173 * model.LotteryMultiple;
                                level[2] += 1;
                            }
                        }
                    }
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
                maxLevel = 4;
                level[0] = level[1] = level[3] = level[4] = level[5] = 0;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;

            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void BX(string[] winSSQList, string[] SSQList, int LotteryChippedID)
        {
            int maxLevel = -1;
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            for (int n = 0; n < SSQList.Length; n++)
            {
                int count = 0;
                string[] fcList = SSQList[n].Split('*');

                for (int j = 0; j < winSSQList.Length; j++)
                {
                    int index = fcList[j].IndexOf(winSSQList[j]);
                    if (index > -1)
                    {
                        count++;
                    }
                    if (count == 2)
                    {
                        isWin = true;
                        winMoney += 693 * model.LotteryMultiple;
                    }
                }
            }
            string winstr = winSSQList[0] + "," + winSSQList[1] + "," + winSSQList[2];
            List<string> lastList = getWinNoSort(winstr);
            for (int n = 0; n < SSQList.Length; n++)
            {
                string[] fcList = SSQList[n].Split('*');

                for (int i = 0; i < lastList.Count; i++)
                {
                    int countFlag = 0;
                    string[] flagList = lastList[i].Split(',');
                    for (int j = 0; j < flagList.Length; j++)
                    {
                        int index = fcList[j].IndexOf(flagList[j]);
                        if (index > -1)
                        {
                            countFlag++;
                        }
                        if (countFlag == 3)
                        {
                            winMoney += 173 * model.LotteryMultiple;
                        }
                    }
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
                maxLevel = 2;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;

            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void Do1D(string[] winSSQList, string[] SSQList, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            int maxLevel = -1;
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            for (int n = 0; n < SSQList.Length; n++)
            {
                string[] fcList = SSQList[n].Split('*');
                for (int j = 0; j < winSSQList.Length; j++)
                {
                    int count = 0;
                    int index = fcList[j].IndexOf(winSSQList[j]);
                    if (index > -1)
                    {
                        count++;
                    }
                    if (count == 1)
                    {
                        winMoney += 10 * model.LotteryMultiple;
                    }
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
                maxLevel = 5;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;

            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void Do2D(string[] winSSQList, string[] SSQList, int LotteryChippedID)
        {
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            int maxLevel = -1;
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            for (int n = 0; n < SSQList.Length; n++)
            {
                string[] fcList = SSQList[n].Split('*');
                int count = 0;
                for (int j = 0; j < winSSQList.Length; j++)
                {
                    int index = fcList[j].IndexOf(winSSQList[j]);
                    if (index > -1)
                    {
                        count++;
                    }
                    if (count == 2)
                    {
                        isWin = true;
                        winMoney += 104 * model.LotteryMultiple;
                    }
                }
            }
            if (winMoney > 0)
            {
                isWin = true;
                maxLevel = 6;
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;

            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void HS(string[] winSSQList, string total, int LotteryChippedID)
        {
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            decimal sum = 0;
            for (int i = 0; i < winSSQList.Length; i++)
            {
                sum += decimal.Parse(winSSQList[i]);
            }
            string[] hslist = total.Split(',');
            for (int i = 0; i < hslist.Length; i++)
            {
                if (sum == decimal.Parse(hslist[i]))
                {
                    isWin = true;
                    if (sum == 0 || sum == 27)
                    {
                        winMoney += 1040 * model.LotteryMultiple;
                    }
                    else if (sum == 1 || sum == 26)
                    {
                        winMoney += 345 * model.LotteryMultiple;
                    }
                    else if (sum == 2 || sum == 25)
                    {
                        winMoney += 172 * model.LotteryMultiple;
                    }
                    else if (sum == 3 || sum == 24)
                    {
                        winMoney += 104 * model.LotteryMultiple;
                    }
                    else if (sum == 4 || sum == 23)
                    {
                        winMoney += 69 * model.LotteryMultiple;
                    }
                    else if (sum == 5 || sum == 22)
                    {
                        winMoney += 49 * model.LotteryMultiple;
                    }
                    else if (sum == 6 || sum == 21)
                    {
                        winMoney += 37 * model.LotteryMultiple;
                    }
                    else if (sum == 7 || sum == 20)
                    {
                        winMoney += 29 * model.LotteryMultiple;
                    }
                    else if (sum == 8 || sum == 19)
                    {
                        winMoney += 23 * model.LotteryMultiple;
                    }
                    else if (sum == 9 || sum == 18)
                    {
                        winMoney += 19 * model.LotteryMultiple;
                    }
                    else if (sum == 10 || sum == 17)
                    {
                        winMoney += 16 * model.LotteryMultiple;
                    }
                    else if (sum == 11 || sum == 16)
                    {
                        winMoney += 15 * model.LotteryMultiple;
                    }
                    else if (sum == 12 || sum == 15)
                    {
                        winMoney += 15 * model.LotteryMultiple;
                    }
                    else if (sum == 13 || sum == 14)
                    {
                        winMoney += 14 * model.LotteryMultiple;
                    }
                }
            }
            model.IsWin = isWin;
            model.WinLevel = 0;
            model.WinMoney = winMoney;
            model.Flag = true;

            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }
        public static void CST(string[] winSSQList, int LotteryChippedID, int fcType, int fcTypeNext)
        {
            int[] level = new int[] { 0, 0, 0, 0, 0, 0 };
            Model.LotteryChipped model = BLL.LotteryChipped.GetModel(LotteryChippedID);
            bool isWin = false;
            decimal winMoney = 0;
            int maxLevel = -1;
            int hs = int.Parse(winSSQList[0]) + int.Parse(winSSQList[1]) + int.Parse(winSSQList[2]);
            string tlj = winSSQList[0] + winSSQList[1] + winSSQList[2];
            if (fcType == 11)
            {
                if (int.Parse(winSSQList[0]) == int.Parse(winSSQList[1]) && int.Parse(winSSQList[1]) == int.Parse(winSSQList[2]))
                {
                    isWin = true;
                    winMoney += 104 * model.LotteryMultiple * model.LotteryCount;
                    maxLevel = 11;
                }
            }
            else if (fcType == 10)
            {
                if (tlj == "012" || tlj == "123" || tlj == "234" || tlj == "345" || tlj == "456" || tlj == "567" || tlj == "678" || tlj == "789"
                    || tlj == "210" || tlj == "321" || tlj == "432" || tlj == "543" || tlj == "654" || tlj == "765" || tlj == "876" || tlj == "987")
                {
                    isWin = true;
                    winMoney += 65 * model.LotteryMultiple * model.LotteryCount;
                    maxLevel = 10;
                }
            }
            else if (fcType == 9)
            {
                string[] lotteryList = model.LotteryNo.Split(',');
                //int a = int.Parse(tlj) % 2;
                foreach (string str in lotteryList)
                {
                    if ((str.Equals("1") && hs >= 19 && hs <= 27) || (str.Equals("2") && hs >= 0 && hs <= 8))
                    {
                        isWin = true;
                        winMoney += 6 * model.LotteryMultiple;
                        maxLevel = 9;
                    }
                    else if ((str.Equals("3") && int.Parse(tlj) % 2 == 1) || (str.Equals("4") && int.Parse(tlj) % 2 == 0))
                    {
                        isWin = true;
                        winMoney += 8 * model.LotteryMultiple;
                        maxLevel = 9;
                    }
                }
            }
            model.IsWin = isWin;
            model.WinLevel = maxLevel;
            model.WinMoney = winMoney;
            model.Flag = true;

            if (BLL.LotteryChipped.Update(model) > 0)
            {
                distributionUserMoney(model);
            }
            sumWinMoney = winMoney;
            addWinInfo(level, model.LotteryType, model.LotteryOpenTime, LotteryChippedID);
        }

        /// <summary>
        /// 将中奖号码排列成不同的组合
        /// </summary>
        /// <param name="winSSQStr"></param>
        /// <returns></returns>
        public static List<string> getWinNoSort(string winSSQStr)
        {
            List<string> lastList = new List<string>();
            //中奖号
            string[] winSSQList = winSSQStr.Split(',');
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (i != j && i != k && j != k)
                        {
                            string listStr = winSSQList[i] + "," + winSSQList[j] + "," + winSSQList[k];
                            lastList.Add(listStr);
                        }
                    }
                }
            }
            return lastList;
        }
        private static int Ccombo(int e, int n)
        {
            if (n <= e)
            {
                var r = Tank(e - n) * Tank(n);
                return r = Tank(e) / r;
            }
            return 0;
        }
        private static int Tank(int e)
        {
            return e == 0 ? 1 : Tank(e - 1) * e;
        }
        private static int Rank(int e, int t)
        {
            var n = e * 1 + t * 1;
            switch (n)
            {
                case 7:
                    return 0;
                case 6:
                    return t == 1 ? 2 : 1;
                case 5:
                    return 3;
                case 4:
                    return 4;
                default:
                    return t == 1 ? 5 : -1;
            }
        }
        private static int combo(int e, int t)
        {
            if (e / 2 < t)
            {
                t = e - t;
            }
            if (e < t || t < 0) return 0;
            if (e >= 0 && t == 0) return 1;
            int n = 1;
            int r = e;
            for (var i = 1; i <= t; i++)
            {
                n *= i;
                if (i < t)
                {
                    r *= e - i;
                }
            }
            return r / n;
        }
        private static int Rankx(int e, int t)
        {
            var n = e * 1 + t * 1;
            switch (n)
            {
                case 7:
                    return 0;
                case 6:
                    return t == 1 ? 1 : 2;
                case 5:
                    return t == 0 ? 2 : 3;
                case 4:
                    return 4;
                case 3:
                    return 5;
                case 2:
                    return e == 0 ? 5 : -1;
                default:
                    return -1;
            }
        }
        /// <summary>
        /// 插入中奖信息
        /// </summary>
        /// <param name="LotteryChippedID">合买id</param>
        private static void addWinInfo(int[] level, int lotteryType, string lotteryQs, int LotteryChippedID)
        {
            //3d直选个数oneCount,组三个数twoCount，组六个数threeCount，其他个数因为用不上所以没存,只存了中奖金额。
            if (lotteryType == 5)
            {
                string sql = string.Format("SELECT top 1 * FROM LotteryAnnouncement WHERE LotteryType={0} and LotteryQS={1}", 5, lotteryQs);
                la = BLL.LotteryAnnouncement.GetModelBySql(sql);
            }
            Model.LotteryAnnouncementMy modelMy = new Model.LotteryAnnouncementMy();
            if (la != null)
            {
                modelMy.oneMoney = la.oneMoney;
                modelMy.twoMoney = la.twoMoney;
                modelMy.threeMoney = la.threeMoney;
                modelMy.fourMoney = la.fourMoney;
                modelMy.fiveMoney = la.fiveMoney;
                modelMy.sixMoney = la.sixMoney;
                modelMy.openTime = la.openTime;
                modelMy.lotteryNo = la.LotteryNo;
            }
            modelMy.oneCount = (int)level[0];
            modelMy.twoCount = (int)level[1];
            modelMy.threeCount = (int)level[2];
            modelMy.fourCount = (int)level[3];
            modelMy.fiveCount = (int)level[4];
            modelMy.sixCount = (int)level[5];
            modelMy.sumMoney = sumWinMoney;
            modelMy.lotteryType = lotteryType;
            modelMy.lotteryQS = lotteryQs;
            modelMy.addTime = DateTime.Now;
            modelMy.isChipped = true;
            modelMy.buyId = LotteryChippedID;
            BLL.LotteryAnnouncementMy.Add(modelMy);
        }
    }
}